﻿@model List<Domain.Entities.WebDepartments>
@{
    ViewBag.Title = "DeptList";
    Layout = "~/views/shared/_LayoutBasic.cshtml";
}
<table>
    <tr>
        <th>
        </th>
        <th>
            ID
        </th>
        <th>
            名称
        </th>
        <th>
            上级
        </th>
    </tr>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <input type="radio" name="MediaIDList" value="@item.DepartmentID" />
                    @Html.Hidden("DepartmentID", item.DepartmentID)
                    @Html.Hidden("DepartmentName", item.DepartmentName)
                </td>
                <td>
                    @item.DepartmentID
                </td>
                <td>
                    @item.DepartmentName
                </td>
                <td>
                    @item.ParentID
                </td>
            </tr>
        }
    </tbody>
    <tfoot>
        <tr>
            <td colspan="4">
                <input type="button" value="选择" id="selectBtn" />
            </td>
        </tr>
    </tfoot>
</table>
<script type="text/javascript">
    $("#selectBtn").click(function () {
        if ($("input[type=radio]:checked").length === 0) {
            return false;
        }

        var deptid, deptname;
        deptid = $("input[type=radio]:checked").nextAll("input[name=DepartmentID]").val();
        deptname = $("input[type=radio]:checked").nextAll("input[name=DepartmentName]").val();

        $("#DepartmentName", window.parent.document).val(deptname);
        $("#DepartmentID", window.parent.document).val(deptid);
        $(".boxy-wrapper", window.parent.document).hide();
    });
</script>
